package com.lanou.musicproject.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;

import com.lanou.musicproject.R;
import com.lanou.musicproject.adapter.SeekContentAdapter;
import com.lanou.musicproject.utils.MyConfig;

/**
 * Created by dllo on 15/10/22.
 * 搜索具体页面里面包含SeekSongFragment,
 * SeekSingerAlbumFRagment,
 * SeekSingerInfoFragment,页面
 */
public class SeekContentActivity extends FragmentActivity {
    private TabLayout mTabLayout;
    private ViewPager viewPager;
    private SeekContentAdapter adapter;
    private FrameLayout seekcontent_framelayout;
    private String url;
    private EditText seekcontent_edit;

    //初始化组件
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seekcontent_activity);


        mTabLayout = (TabLayout) findViewById(R.id.seekcontent_tablayout);
        viewPager = (ViewPager) findViewById(R.id.seekcontent_viewPager);
        seekcontent_framelayout = (FrameLayout) findViewById(R.id.seekcontent_framelayout);

        seekcontent_edit = (EditText) findViewById(R.id.seekcontent_edit);

        seekcontent_framelayout.setOnClickListener(new View.OnClickListener() {
            @Override
            //跳转回搜索页面
            public void onClick(View v) {

                Intent intent = new Intent(SeekContentActivity.this, SeekActivity.class);
                startActivity(intent);
                finish();
            }
        });
        initData();
    }

    private void initData() {
        adapter = new SeekContentAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        mTabLayout.setupWithViewPager(viewPager);
        mTabLayout.setTabsFromPagerAdapter(adapter);
        //得到SeekActivity的传值
        Intent intent = getIntent();
        if (intent != null) {
            String str = intent.getStringExtra("url");
            String s = intent.getStringExtra("seek_title");

            seekcontent_edit.setText(s);

            Log.i("--------------->>>", "*******" + str);
            //得到的值出入缓存中
            MyConfig.putSharePre(SeekContentActivity.this, "Seekcontent", "url", str);
        }

    }
}
